package pkg

import (
	"fmt"
	"github.com/fastwego/wxpay"
	"github.com/fastwego/wxpay/apis/order"
	"github.com/fastwego/wxpay/types"
	"github.com/fastwego/wxpay/util"
	"github.com/spf13/viper"
)

func PayBy() {
	// 微信支付 实例

	pay := wxpay.New(wxpay.Config{
		Appid:  "APPID",
		Mchid:  "MCHID",
		ApiKey: "APIKEY",
		//IsSandBoxMode: true,
		Cert: "CERT",
	})

	// 统一下单
	params := map[string]string{
		"appid":            pay.Config.Appid,
		"mch_id":           pay.Config.Mchid,
		"nonce_str":        util.GetRandString(32),
		"body":             "BODY",
		"out_trade_no":     "NO.10086",
		"spbill_create_ip": "12.123.14.223",
		"notify_url":       viper.GetString("NOTIFYURL"),
		"trade_type":       types.TradeTypeAPP,
	}
	result, err := order.UnifiedOrder(pay, params)
	fmt.Println(result, err)

	if err != nil {
		return
	}

	// 返回客户端预下单信息
	//result["prepay_id"]

}
